package com.ekang.admin.dao;

import com.ekang.admin.model.Order;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * Created by zcz on 2017/10/26.
 */
@Mapper
public interface OrderMapper {

    @Select("select * from torder where orderId=#{id}")
    Order getOrderById(@Param("id") Integer id);

    @Select("select * from torder where orderNO=#{orderNO}")
    Order getOrderbyOrderNO(@Param("orderNO") String orderNO);

    @Select("select * from torder where status>0 and userId=#{userId} order by  addTime desc")
    List<Order> getUserOrderList(@Param("userId") String userId);

    @Insert({
            "insert into torder(qty,goodsId,goodsName,imgUrl,amount,userId,userName,status,addTime,tableNO,tableName,orderNO,wxOrderNO) values (#{u.qty},#{u.goodsId},#{u.goodsName},#{u.imgUrl},#{u.amount},#{u.userId},#{u.userName},#{u.status},#{u.addTime},#{u.tableNO},#{u.tableName},#{u.orderNO},#{u.wxOrderNO})"
    })
    int insertOrder(@Param("u") Order order);

    @Update("update torder set status=#{u.status} where orderId=#{u.orderId} limit 1")
    int updateOrderById(@Param("u") Order order);


    @Update("update torder set wxOrderNO=#{u.wxOrderNO} where orderNO=#{u.orderNO} limit 1")
    int updateOrderPayByNO(@Param("u") Order order);


    @Update("update torder set status=#{u.status} where orderNO=#{u.orderNO} limit 1")
    int updateOrderPayed(@Param("u") Order order);


    @Select("select * from torder where status>0  order by  addTime desc")
    List<Order> getOrderList();


}
